const express = require('express');
const router = express.Router();
const adminController = require('../controllers/adminController');
const adminAuthMiddleware = require('../middlewares/adminAuthMiddleware');

// 不需要验证的路由
router.post('/login', adminController.login);

// 需要验证的路由
router.use(adminAuthMiddleware);  // 应用中间件到以下所有路由

// 数据统计 - 放在最前面以避免路径冲突
router.get('/statistics', adminController.getStatistics);

// 管理员管理
router.post('/create', adminController.createAdmin);

// 用户管理
router.get('/users', adminController.getAllUsers);
router.put('/users/:userId', adminController.updateUser);
router.delete('/users/:userId', adminController.deleteUser);

// 商品管理
router.get('/products', adminController.getAllProducts);
router.post('/products', adminController.createProduct);
router.put('/products/:productId', adminController.updateProduct);
router.delete('/products/:productId', adminController.deleteProduct);

// 订单管理
router.get('/orders', adminController.getAllOrders);
router.put('/orders/:orderId/status', adminController.updateOrderStatus);
router.delete('/orders/:orderId', adminController.deleteOrder);
router.get('/orders/:orderId', adminController.getOrderDetail);

// 仪表盘数据
router.get('/dashboard', adminController.getDashboardData);

// 修改密码
router.post('/change-password', adminController.changePassword);

// 获取拼团列表
router.get('/groupbuy/list', adminAuthMiddleware, adminController.getGroupBuyList);

module.exports = router; 